﻿Ext.define('Examples.order.order.view.Form', {
    extend: 'Happy.form.Panel',
    alias: 'widget.order-form',
    requires: [
        'Happy.form.action.Close',
        'Happy.form.action.Save',
        'Happy.form.field.Checkbox',
        'Happy.form.field.CkEditor',
        'Happy.form.field.Combobox',
        'Happy.form.field.TreeCombobox',
        'Happy.form.CheckboxGroup',
        'Happy.form.ImageContainer',
        'Happy.form.LinkContainer',
        'Examples.order.orderitem.view.Grid'
    ],

    items: [{
        fieldLabel: 'Customer',
        name: 'Customer',
        allowBlank: false
    }],

    initComponent: function () {
        var me = this;

        me.buttons = Happy.createActions([
            'save',
            'close'
        ]);

        me.callParent(arguments);
    },

    configRelatedItems: function () {
        var me = this;

        me.childrenGridPanel = me.addDocked({
            xtype: 'tabpanel',
            height: 200,
            dock: 'bottom',
            items: [{
                title: 'orderitem',
                xtype: 'orderitem-grid'
            }]
        }, 1);

        me.on('recordloaded', function (form, record) {
            var grid = me.childrenGridPanel[0].down('orderitem-grid');
            grid.reconfigure(record.OrderItems);
            grid.reSelect();
        });
    }
});